package usj.frames;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import usj.util.Configuracion;

public class ConfiguracionFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JFrame frame;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JButton button;
	private JLabel label;
	private JTextField textField_6;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					new ConfiguracionFrame();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}*/

	/**
	 * Create the frame.
	 */
	public ConfiguracionFrame() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);

		frame.getContentPane().setLayout(null);
		
		label = new JLabel("Host Cliente:");
		label.setVisible(false);
		label.setBounds(81, 14, 79, 14);
		frame.getContentPane().add(label);
		
		JLabel lblNewLabel = new JLabel("Host Destino:");
		lblNewLabel.setBounds(81, 39, 79, 14);
		frame.getContentPane().add(lblNewLabel);
		
		JLabel lblPuerto = new JLabel("Puerto SMTP:");
		lblPuerto.setBounds(81, 64, 79, 14);
		frame.getContentPane().add(lblPuerto);
		
		JLabel lblPuertoPop = new JLabel("Puerto POP3:");
		lblPuertoPop.setBounds(81, 89, 79, 14);
		frame.getContentPane().add(lblPuertoPop);
		
		JLabel lblUsuario = new JLabel("Usuario:");
		lblUsuario.setBounds(81, 114, 79, 14);
		frame.getContentPane().add(lblUsuario);
		
		JLabel lblContrasea = new JLabel("Contrase\u00F1a:");
		lblContrasea.setBounds(81, 139, 79, 14);
		frame.getContentPane().add(lblContrasea);
		
		JLabel lblEmail = new JLabel("Email Remitente:");
		lblEmail.setBounds(81, 164, 99, 14);
		frame.getContentPane().add(lblEmail);
		
		textField = new JTextField();
		textField.setBounds(197, 36, 125, 20);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(197, 61, 60, 20);
		frame.getContentPane().add(textField_1);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(197, 86, 60, 20);
		frame.getContentPane().add(textField_2);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(197, 111, 125, 20);
		frame.getContentPane().add(textField_3);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setBounds(197, 136, 125, 20);
		frame.getContentPane().add(textField_4);
		
		textField_5 = new JTextField();
		textField_5.setColumns(10);
		textField_5.setBounds(197, 161, 161, 20);
		frame.getContentPane().add(textField_5);
		
		textField_6 = new JTextField();
		textField_6.setVisible(false);
		textField_6.setColumns(10);
		textField_6.setBounds(197, 11, 125, 20);
		frame.getContentPane().add(textField_6);
		
		JButton btnGuardar = new JButton("Guardar");
		btnGuardar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Configuracion.getInstance().setProperty(Configuracion.hostCliente, textField_6.getText());
				Configuracion.getInstance().setProperty(Configuracion.hostDestino, textField.getText());
				Configuracion.getInstance().setProperty(Configuracion.puertoSMTP, textField_1.getText());
				Configuracion.getInstance().setProperty(Configuracion.puertoPOP3, textField_2.getText());
				Configuracion.getInstance().setProperty(Configuracion.usuario, textField_3.getText());
				Configuracion.getInstance().setProperty(Configuracion.pass, textField_4.getText());
				Configuracion.getInstance().setProperty(Configuracion.email, textField_5.getText());
				Configuracion.save();
				frame.dispose();
			}
		});
		btnGuardar.setBounds(91, 203, 89, 23);
		frame.getContentPane().add(btnGuardar);
		
		button = new JButton("Salir");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
		button.setBounds(223, 203, 89, 23);
		frame.getContentPane().add(button);
		

		cargarDatos();
	}
	
	private void cargarDatos(){
		textField_6.setText(Configuracion.getInstance().getProperty(Configuracion.hostCliente));
		textField.setText(Configuracion.getInstance().getProperty(Configuracion.hostDestino));
		textField_1.setText(Configuracion.getInstance().getProperty(Configuracion.puertoSMTP));
		textField_2.setText(Configuracion.getInstance().getProperty(Configuracion.puertoPOP3));
		textField_3.setText(Configuracion.getInstance().getProperty(Configuracion.usuario));
		textField_4.setText(Configuracion.getInstance().getProperty(Configuracion.pass));
		textField_5.setText(Configuracion.getInstance().getProperty(Configuracion.email));
	}
}
